package org.nf.shopping.controller;

import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.nf.shopping.common.vo.ResultVO;
import org.nf.shopping.entity.User;
import org.nf.shopping.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author czl
 * @Date 2024-12-18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController extends BaseController{

    private final UserService userService;

    @GetMapping("/listUser")
    public ResultVO<PageInfo<User>> listUser(Integer limit, Integer page, String name){
        PageInfo<User> pageInfo = userService.listUser(limit, page, name);
        return success(pageInfo);
    }

    @PostMapping("/updateUser")
    public ResultVO updateUser(User user){
        userService.updateUser(user);
        return success();
    }

    @PostMapping("/deloneUser")
    public ResultVO deloneUser(Integer id){
        userService.deloneUser(id);
        return success();
    }

    @PostMapping("/addUser")
    public ResultVO addCommodity(User user){
        userService.addUser(user);
        return success();
    }

    @PostMapping("/getUserList")
    public ResultVO<List<User>> getUserList(){
        return success(userService.getUserList());
    }
}
